package com.itheima.Cookie.c_age;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/servlet/killCookieServlet")
public class KillCookieServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1. 再创建一个同名的Cookie
        Cookie cookie = new Cookie("autoLogin", "");

        //2. 设置持久化保存时间为0
        cookie.setMaxAge(0);

        //3. 设置相同的有效访问路径
        cookie.setPath(request.getContextPath());

        //4. 返回浏览器端覆盖原来的Cookie
        response.addCookie(cookie);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
